package com.yuting.client;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;

/**
 *
 * @author cyt
 * @date 2020/6/28
 */
public class ClientInitClose {

    private Socket s;

    public ObjectInputStream getOis() {
        return ois;
    }

    public ObjectOutputStream getOos() {
        return oos;
    }

    private ObjectInputStream ois;

    private ObjectOutputStream oos;
    /**
     * 初始化客户端
     */
    public void clientInit() throws IOException {

        s = new Socket(InetAddress.getLocalHost(),8099);
        System.out.println("连接服务器成功！");
        //初始化输入流和输出流
        //这里需要注意的是客户端必须先初始化oos，再ois,否则会堵塞
        this.oos = new ObjectOutputStream(s.getOutputStream());
        this.ois = new ObjectInputStream(s.getInputStream());



    }

    /**
     * 关闭客户端
     * @throws IOException
     */
    public void clientClose() throws IOException {
        ois.close();
        oos.close();
        s.close();
        System.out.println("关闭客户端成功！");
    }

}
